package expriment3_bag;

public class Six {
    public static void main(String[] args) {
        int aa[][]={ { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };
        int [][]bb=new int[aa[0].length][aa.length];
        System.out.println("原来的数组为：");
        for(int i=0;i<aa.length;i++){
            for(int j: aa[i]){
                System.out.print(j+"\t");
            }
            System.out.println();
        }
        System.out.println();
        System.out.println("转置后的数组为：");
        System.out.println();
        for(int i=0;i<bb.length;i++){
            for(int j=0;j<bb[i].length;j++){
                bb[i][j]=aa[j][i];
            }
        }
        for (int i = 0; i < bb.length; i++) {
            for (int j = 0; j < bb[i].length; j++) {
                System.out.print(bb[i][j]+"\t");
            }
            System.out.println();
        }
        System.out.println();
        System.out.println("----以上为本人书写的代码------");
        System.out.println();
        System.out.println("----以下为实验书上的代码------");
        int a[][] = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };
        int b[][] = new int[4][3];
        int i, j;
        System.out.println("-----原数组-----");
        for (i = 0; i < 3; i++) {
            for (int s : a[i])
                System.out.print(s + " ");
            System.out.println();
        }
        System.out.println("-----转置后-----");
        for (i = 0; i < 3; i++)
            for (j = 0; j < 4; j++)
                b[j][i] = a[i][j];
        for (i = 0; i < 4; i++) {
            for (int s : b[i])
                System.out.print(s + " ");
            System.out.println();
        }
        System.out.println("----------");
    }
}
